﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MS.InformationManagement.DAL.DocumentCenter;
using Microsoft.SharePoint;
using MS.InformationManagement.Support.Constants;
using MS.InformationManagement.Support;
using MS.InformationManagement.Core.Support;

namespace MS.InformationManagement.BLL.FilesUploader
{
    public class FilesUploader
    {

        public void SaveDocumentsCurrentLibrary(List<FileEntity> SelectedFiles, string ListId)
        {
            foreach (FileEntity file in SelectedFiles)
            {
                SPFile newFile = SPContext.Current.Web.Lists[new Guid(ListId)].RootFolder.Files.Add(file.FileName, file.FileContent);
                newFile.Item[SPBuiltInFieldId.ContentType] = GlobalConstants.CTTN_ARCHIVE;
                newFile.Item[CustomSiteColumns.FIELD_DOCSET_KIND] = TermStoreHelper.GetTaxonomyFieldByTerm(GlobalConstants.METADATA_GROUP_NAME, GlobalConstants.METADATA_TERM_TIPOS, GlobalConstants.METADATA_TERM_TIPO_SIN_RADICADO);
                newFile.Item[CustomSiteColumns.FIELD_DOCUMENT_STATUS] = TermStoreHelper.GetTaxonomyFieldByTerm(GlobalConstants.METADATA_GROUP_NAME, GlobalConstants.METADATA_TERM_STATUS, GlobalConstants.METADATA_TERM_STATUS_SIN_RADICADO);
                newFile.Item[CustomSiteColumns.FIELD_DOCSET_ID_RADICADO] = file.FileName;
                newFile.Log(string.Empty, DateTime.Now, InformationManagement.Support.Enums.TraceableOperation.Creación, SPContext.Current.Web.CurrentUser.Name, string.Empty);
                newFile.Item.SystemUpdate();
            }
        }

    }
}
